﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Brain
{
    public class LoadingScreen : GameScreen
    {
        public ILoadable Screen;

        public bool Ended;

        /// <summary>
        /// An Asynchronous Game Screen
        /// </summary>
        /// <param name="screen"></param>
        public LoadingScreen(ILoadable screen)
        {
            this.Screen = screen;
            ThreadPool.QueueUserWorkItem(WaitCallback);
        }
        void WaitCallback(object state)
        {
            Screen.Load();
            Ended = true;
        }

        public override void Draw()
        {
            base.Draw();

            if (Ended)
            {
                Engine.Instance.ScreenManager.RemoveScreen(this);
            }
        }
    }
}
